package com.silence.ByteDance;

import java.util.*;

// 加一操作
public class normal_45 {
    public static String solution(int n, int k, String numStr) {
        // Please write your code here
        // n 初始长度  k 操作次数
        String[] strings = numStr.split("");
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(Integer.valueOf(strings[i]));
        }
        for (int i = 1; i <= k; i++) {
            int index = 0;
            while (index < list.size()) {
                int now = list.get(index);
                if (now == 9) {
                    list.set(index, 0);
                    list.add(index, 1);
                    index++;
                } else {
                    list.set(index, list.get(index) + 1);
                }
                index++;
            }
        }
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < list.size() - 1; i++) {
            stringBuilder.append(list.get(i));
        }
        stringBuilder.append(list.get(list.size() - 1));
        return stringBuilder.toString();
    }

    public static void main(String[] args) {
        // You can add more test cases here
        System.out.println(solution(3, 1, "798").equals("8109"));
        System.out.println(solution(3, 3, "798").equals("103221"));
    }
}
